package com.test.mooan.labama.view_boom.info_input_boom;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.test.mooan.labama.R;
import com.test.mooan.labama.bean_boom.process_boom.ProcessData_boom;
import com.test.mooan.labama.utils_boom.helper_boom.UserInfoHelper_boom;
import com.test.mooan.labama.view_boom.base_boom.BaseInfoInputViewManager_boom;


public class GenderSelectViewManager_boom extends BaseInfoInputViewManager_boom {

    private TextView titleTv;
    private View maleLayout,femaleLayout;
    private TextView maleTv, femaleTv;
    private ImageView maleSelectIv,femaleSelectIv;

    private boolean isMale = true;

    private static final String up_male="MALE",up_female="FEMALE";

    public GenderSelectViewManager_boom(View view, ProcessData_boom data, String pageTag){
        super(view,data,pageTag);
    }

    @Override
    protected void init(){

        titleTv = mView.findViewById(R.id.view_gender_select_tv_title);
        maleLayout = mView.findViewById(R.id.view_gender_select_layout_male);
        femaleLayout = mView.findViewById(R.id.view_gender_select_layout_female);
        maleTv = mView.findViewById(R.id.view_gender_select_tv_male);
        femaleTv = mView.findViewById(R.id.view_gender_select_tv_female);
        maleSelectIv = mView.findViewById(R.id.view_gender_select_iv_male);
        femaleSelectIv = mView.findViewById(R.id.view_gender_select_iv_female);

        maleLayout.setOnClickListener(v -> setGender(true));
        femaleLayout.setOnClickListener(v -> setGender(false));

        setTitle(mData.gTitle());

    }

    @Override
    public boolean checkInput() {
        return true;
    }

    @Override
    public String getInput() {
        return isMale ? "MALE":"FEMALE";
    }

    public void setGender(boolean isMale){
        this.isMale = isMale;
        if (isMale){
            UserInfoHelper_boom.gInstance().addEventPoint((pageTag + "_" + mData.gParamName()+"_INPUT").toUpperCase(),up_male);
            maleTv.setTextColor(ContextCompat.getColor(mView.getContext(),R.color.black));
            femaleTv.setTextColor(ContextCompat.getColor(mView.getContext(),R.color.gray_d));
            maleSelectIv.setBackgroundResource(R.drawable.icon_item_check_true);
            femaleSelectIv.setBackgroundResource(R.drawable.icon_item_check_false);
        }else {
            UserInfoHelper_boom.gInstance().addEventPoint((pageTag + "_" + mData.gParamName()+"_INPUT").toUpperCase(),up_female);
            maleTv.setTextColor(ContextCompat.getColor(mView.getContext(),R.color.gray_d));
            femaleTv.setTextColor(ContextCompat.getColor(mView.getContext(),R.color.black));
            maleSelectIv.setBackgroundResource(R.drawable.icon_item_check_false);
            femaleSelectIv.setBackgroundResource(R.drawable.icon_item_check_true);
        }
    }

    public void setTitle(String title){
        if (TextUtils.isEmpty(title)) titleTv.setVisibility(GONE);
        else {
            titleTv.setVisibility(VISIBLE);
            titleTv.setText(title);
        }
    }

}
